package com.mh.service.impl;

import com.mh.dto.R;
import com.mh.pojo.PageElements;
import com.mh.service.PageElementService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Date:2024/10/19
 * author:zmh
 * description:页面节点内容数据实现类
 **/

@Service
@RequiredArgsConstructor
@Slf4j
public class PageElementServiceImpl implements PageElementService {

    private final MongoTemplate mongoTemplate;


    @Override
    public R<List<PageElements>> getPageElementsByPosition(String showPosition) {
        // 构建查询条件
        Query query = new Query().addCriteria(Criteria.where("showPosition").is(showPosition));
        List<PageElements> pageElements = mongoTemplate.find(query, PageElements.class);
        if (pageElements.isEmpty()) {
            return R.error("节点元素内容数据为空");
        }
        return R.success(pageElements);
    }
}
